package com.manshutingyu.system.api.factory;

import com.manshutingyu.common.core.dto.LoginUserDTO;
import com.manshutingyu.common.core.dto.R;
import com.manshutingyu.system.api.domain.SysUserDTO;
import com.manshutingyu.system.api.feign.RemoteSysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author：yinyuxia
 * @Date：2025/4/25 15:14
 */
@Component
@Slf4j
public class RemoteSysUseFallbackFactory  implements FallbackFactory<RemoteSysUserService> {

    @Override
    public RemoteSysUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSysUserService() {
            @Override
            public R<SysUserDTO> getById(Long id) {
                return R.error("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUserDTO> loadUserByUsername(String username) {
                return R.error("根据用户名获取用户信息异常:" + throwable.getMessage());
            }
        };
    }
}
